<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>节点练习 - 删除节点</title>
  </head>

  <body>
    <div id="three" class="three">
      我是three内容
      <ul>
        <li>简简单单的早餐</li>
        <li class="font-color">简简单单的午饭</li>
        <li>简简单单的晚饭</li>
      </ul>
    </div>
    <button onclick="btn_remove_one()">删除第一个节点</button>
    <button onclick="btn_remove_two()">删除第三个节点</button>
    <button onclick="btn_remove_three()">删除最后一个节点</button>
    <hr />
    <button onclick="btn_remove_class()">删除第二个节点的样式</button>
    <script>
      x = document.getElementById("three").getElementsByTagName("ul")[0];
      y = x.getElementsByTagName("li");
      //删除第一个节点
      const btn_remove_one = () => {
        x.removeChild(y[0]);
      };

      //删除第三个节点
      const btn_remove_two = () => {
        x.removeChild(y[2]);
      };
      //一直删除最后一个节点
      const btn_remove_three = () => {
        console.log(x);
        console.log(x.lastElementChild.innerHTML);
        x.removeChild(x.lastElementChild);
      };

      //删除节点属性（class）
      const btn_remove_class = () => {
        y[1].setAttribute("class", "");
      };
    </script>

    <style>
      .font-color {
        color: tomato;
      }
    </style>
  </body>
</html>
